package net.sinmetal.twitcockpit.form.cockpit.schedule;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import net.sinmetal.twitcockpit.model.constant.SchedulePostType;

import org.slim3.util.BeanUtil;

/**
 * CockPitScheduleAutoPostForm
 *
 * @author Sinmetal
 *
 */
public class AutoPostForm {

    private String id;

    private String tweet;

    private Integer weekCheckbox1;

    private Integer weekCheckbox2;

    private Integer weekCheckbox3;

    private Integer weekCheckbox4;

    private Integer weekCheckbox5;

    private Integer weekCheckbox6;

    private Integer weekCheckbox7;

    private Integer startyear;

    private Integer startmonth;

    private Integer startday;

    private Integer starthour;

    private Integer startminute;

    private Integer endyear;

    private Integer endmonth;

    private Integer endday;

    private Integer endhour;

    private Integer endminute;

    /**
     * @return id
     */
    public String getId() {
        return id;
    }

    /**
     * @param id
     *            セットする id
     */
    public void setId(String id) {
        this.id = id;
    }

    /**
     * @return tweet
     */
    public String getTweet() {
        return tweet;
    }

    /**
     * @param tweet
     *            セットする tweet
     */
    public void setTweet(String tweet) {
        this.tweet = tweet;
    }

    /**
     * @return weekCheckbox1
     */
    public Integer getWeekCheckbox1() {
        return weekCheckbox1;
    }

    /**
     * @param weekCheckbox1
     *            セットする weekCheckbox1
     */
    public void setWeekCheckbox1(Integer weekCheckbox1) {
        this.weekCheckbox1 = weekCheckbox1;
    }

    /**
     * @return weekCheckbox2
     */
    public Integer getWeekCheckbox2() {
        return weekCheckbox2;
    }

    /**
     * @param weekCheckbox2
     *            セットする weekCheckbox2
     */
    public void setWeekCheckbox2(Integer weekCheckbox2) {
        this.weekCheckbox2 = weekCheckbox2;
    }

    /**
     * @return weekCheckbox3
     */
    public Integer getWeekCheckbox3() {
        return weekCheckbox3;
    }

    /**
     * @param weekCheckbox3
     *            セットする weekCheckbox3
     */
    public void setWeekCheckbox3(Integer weekCheckbox3) {
        this.weekCheckbox3 = weekCheckbox3;
    }

    /**
     * @return weekCheckbox4
     */
    public Integer getWeekCheckbox4() {
        return weekCheckbox4;
    }

    /**
     * @param weekCheckbox4
     *            セットする weekCheckbox4
     */
    public void setWeekCheckbox4(Integer weekCheckbox4) {
        this.weekCheckbox4 = weekCheckbox4;
    }

    /**
     * @return weekCheckbox5
     */
    public Integer getWeekCheckbox5() {
        return weekCheckbox5;
    }

    /**
     * @param weekCheckbox5
     *            セットする weekCheckbox5
     */
    public void setWeekCheckbox5(Integer weekCheckbox5) {
        this.weekCheckbox5 = weekCheckbox5;
    }

    /**
     * @return weekCheckbox6
     */
    public Integer getWeekCheckbox6() {
        return weekCheckbox6;
    }

    /**
     * @param weekCheckbox6
     *            セットする weekCheckbox6
     */
    public void setWeekCheckbox6(Integer weekCheckbox6) {
        this.weekCheckbox6 = weekCheckbox6;
    }

    /**
     * @return weekCheckbox7
     */
    public Integer getWeekCheckbox7() {
        return weekCheckbox7;
    }

    /**
     * @param weekCheckbox7
     *            セットする weekCheckbox7
     */
    public void setWeekCheckbox7(Integer weekCheckbox7) {
        this.weekCheckbox7 = weekCheckbox7;
    }

    /**
     * @return startyear
     */
    public Integer getStartyear() {
        return startyear;
    }

    /**
     * @param startyear
     *            セットする startyear
     */
    public void setStartyear(Integer startyear) {
        this.startyear = startyear;
    }

    /**
     * @return startmonth
     */
    public Integer getStartmonth() {
        return startmonth;
    }

    /**
     * @param startmonth
     *            セットする startmonth
     */
    public void setStartmonth(Integer startmonth) {
        this.startmonth = startmonth;
    }

    /**
     * @return startday
     */
    public Integer getStartday() {
        return startday;
    }

    /**
     * @param startday
     *            セットする startday
     */
    public void setStartday(Integer startday) {
        this.startday = startday;
    }

    /**
     * @return starthour
     */
    public Integer getStarthour() {
        return starthour;
    }

    /**
     * @param starthour
     *            セットする starthour
     */
    public void setStarthour(Integer starthour) {
        this.starthour = starthour;
    }

    /**
     * @return startminute
     */
    public Integer getStartminute() {
        return startminute;
    }

    /**
     * @param startminute
     *            セットする startminute
     */
    public void setStartminute(Integer startminute) {
        this.startminute = startminute;
    }

    /**
     * @return endyear
     */
    public Integer getEndyear() {
        return endyear;
    }

    /**
     * @param endyear
     *            セットする endyear
     */
    public void setEndyear(Integer endyear) {
        this.endyear = endyear;
    }

    /**
     * @return endmonth
     */
    public Integer getEndmonth() {
        return endmonth;
    }

    /**
     * @param endmonth
     *            セットする endmonth
     */
    public void setEndmonth(Integer endmonth) {
        this.endmonth = endmonth;
    }

    /**
     * @return endday
     */
    public Integer getEndday() {
        return endday;
    }

    /**
     * @param endday
     *            セットする endday
     */
    public void setEndday(Integer endday) {
        this.endday = endday;
    }

    /**
     * @return endhour
     */
    public Integer getEndhour() {
        return endhour;
    }

    /**
     * @param endhour
     *            セットする endhour
     */
    public void setEndhour(Integer endhour) {
        this.endhour = endhour;
    }

    /**
     * @return endminute
     */
    public Integer getEndminute() {
        return endminute;
    }

    /**
     * @param endminute
     *            セットする endminute
     */
    public void setEndminute(Integer endminute) {
        this.endminute = endminute;
    }

    /**
     * WeekCheckBoxのうち、ONになっているもののValueを返す
     *
     * @return
     */
    public List<Integer> getWeekCheckBoxOnList() {
        Integer[] weekCheckBoxArray =
            {
                this.weekCheckbox1,
                this.weekCheckbox2,
                this.weekCheckbox3,
                this.weekCheckbox4,
                this.weekCheckbox5,
                this.weekCheckbox6,
                this.weekCheckbox7 };
        List<Integer> weekCheckBoxOnList = new ArrayList<Integer>();
        for (Integer weekCheckBox : weekCheckBoxArray) {
            if (weekCheckBox == null) {
                continue;
            }
            weekCheckBoxOnList.add(weekCheckBox);
        }
        return weekCheckBoxOnList;
    }

    /**
     * Schudeles 設定
     *
     * @param schedules
     */
    public void setSchedules(List<SchedulePostType> schedules) {
        for (SchedulePostType postType : schedules) {
            int value = postType.getValue();
            switch (value) {
            case 1:
                this.weekCheckbox1 = value;
                break;
            case 2:
                this.weekCheckbox2 = value;
                break;
            case 3:
                this.weekCheckbox3 = value;
                break;
            case 4:
                this.weekCheckbox4 = value;
                break;
            case 5:
                this.weekCheckbox5 = value;
                break;
            case 6:
                this.weekCheckbox6 = value;
                break;
            case 7:
                this.weekCheckbox7 = value;
                break;
            default:
                break;
            }
        }
    }

    /**
     * Schudules 取得
     *
     * @return
     */
    public List<SchedulePostType> getSchedules() {
        List<SchedulePostType> schedules = new ArrayList<SchedulePostType>();

        List<Integer> weekCheckBoxOnList = getWeekCheckBoxOnList();
        for (Integer weekCheckBox : weekCheckBoxOnList) {
            schedules.add(SchedulePostType.parse(weekCheckBox));
        }
        return schedules;
    }

    /**
     * インスタンス生成
     *
     * @param requestMap
     * @return
     */
    public static AutoPostForm getInstance(Map<String, Object> requestMap) {
        AutoPostForm instance = new AutoPostForm();
        BeanUtil.copy(requestMap, instance);
        return instance;
    }

    /**
     * インスタンス生成
     *
     * @param autoPostVar
     * @return
     */
    public static AutoPostForm getInstance(Object obj) {
        AutoPostForm instance = new AutoPostForm();
        BeanUtil.copy(obj, instance);
        return instance;
    }
}
